import 'package:flutter/material.dart';
import 'package:wit_shoes/define/define_colors.dart';

class WidgetTools {
  MaterialButton createMaterialButton(double buttonWidth, String title,
      Color bgColor, Color textColor, double borderWidth, buttonAction,
      {double radius = 0}) {
    // 边框样式
    RoundedRectangleBorder shape = RoundedRectangleBorder(
      side: BorderSide(
        width: borderWidth,
        color: borderWidth == 0 ? Colors.white : Colors.blue,
      ),
      borderRadius: BorderRadius.all(
        Radius.circular(radius),
      ),
    );

    Text textWidget = Text(
      title,
      style: const TextStyle(
        fontSize: 15,
        fontWeight: FontWeight.bold,
      ),
    );
    //生成按钮
    return MaterialButton(
      color: bgColor,
      textColor: textColor,
      minWidth: buttonWidth,
      height: 49,
      shape: shape,
      onPressed: () {
        if (buttonAction != null) {
          buttonAction!();
        }
      },
      child: textWidget,
    );
  }

  // *
  /// -  @description: 自定义按钮
  /// -  @Date: 2022-06-30 15:49
  /// -  @parm: buttonWidth 按钮宽度
  ///           title 按钮标题
  ///           buttonAction 点击方法
  ///           bgColor颜色
  ///           textColor 字体颜色
  ///           borderWidth 边框宽度
  ///           borderColor 边框颜色
  ///           radius圆角
  ///           fontSize 字体大小
  ///           fontWeight 加粗
  ///           height 按钮高度
  /// -  @return {*}
  ///
  Widget createCustomInkWellButton(
    String title,
    buttonAction, {
    double? buttonWidth,
    Color? bgColor,
    Color? textColor,
    double borderWidth = 0.0,
    Color? borderColor,
    double radius = 0.0,
    double fontSize = 15,
    FontWeight? fontWeight,
    double height = 49,
    BoxShadow? shadow,
    Image? leftImage,
  }) {
    // 边框样式
    RoundedRectangleBorder shape = RoundedRectangleBorder(
      side: BorderSide(
        width: borderWidth,
        color: borderColor ?? Colors.white,
      ),
      borderRadius: BorderRadius.all(
        Radius.circular(radius),
      ),
    );

    Text textWidget = Text(
      title,
      style: TextStyle(
        fontSize: fontSize,
        fontWeight: fontWeight,
        color: textColor,
      ),
      textAlign: TextAlign.center,
      // maxLines: 1,
    );

    Widget lView;
    if (leftImage != null) {
      lView = leftImage;
    } else {
      lView = const SizedBox();
    }
    //生成按钮
    return Container(
      width: buttonWidth,
      height: height,
      alignment: Alignment.center,
      padding: const EdgeInsets.only(left: 5, right: 5),
      decoration: BoxDecoration(
        color: bgColor,
        borderRadius: BorderRadius.all(Radius.circular(radius)),
        boxShadow: [
          shadow ??
              const BoxShadow(
                color: CustomColors.buttonColor,
                offset: Offset(0, 0),
                blurRadius: 6,
                spreadRadius: 2,
              ),
        ],
      ),
      child: InkWell(
        onTap: () {
          if (buttonAction != null) {
            buttonAction!();
          }
        },
        child: Row(children: [
          lView,
          Expanded(child: textWidget),
        ]),
      ),
    );
  }
}
